package com.atguigu.day03;

import org.apache.flink.streaming.api.datastream.ConnectedStreams;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.co.CoMapFunction;

public class Flink07_Transform_Connect {
    public static void main(String[] args) throws Exception {
        //1.获取流的执行环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        env.setParallelism(1);

        //获取字母流
        DataStreamSource<String> strSource = env.fromElements("a", "b", "c", "d");

        //获取数字流
        DataStreamSource<Integer> intSource = env.fromElements(1, 2, 3, 4, 5);

        //TODO 使用Connect连接两条流，只是机械的合并到一起 同床异梦
        ConnectedStreams<String, Integer> connectedStreams = strSource.connect(intSource);

        SingleOutputStreamOperator<String> result = connectedStreams.map(new CoMapFunction<String, Integer, String>() {
            @Override
            public String map1(String value) throws Exception {
                return value + "字母流";
            }

            @Override
            public String map2(Integer value) throws Exception {
                return value * value + "";
            }
        });

        result.print();

        env.execute();

    }
}
